#!/usr/bin/bash

SCRIPT_PATH=`realpath $0`
SCRIPT_DIR=`dirname ${SCRIPT_PATH}`

cd ${SCRIPT_DIR}

function ret_validate {
    retVal=$?
    if [[ ${retVal} -ne 0 ]]; then
        echo "## FAILED"
        exit ${retVal}
    fi
    echo "## PASSED"
}


echo "## Generating Ent models"
cd components/models && go generate ./ent
ret_validate

echo "## Generating swagger"
go install github.com/swaggo/swag/cmd/swag@latest
cd ${SCRIPT_DIR}/components/server
swag init -g server.go  --parseDependency --parseInternal --parseDepth 1 -d ./,../../components/auth,../../components/repository,../../components/httputils
ret_validate